package com.ruoyi.edh.service.impl;

import java.math.BigDecimal;
import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.edh.domain.EdhProfit;
import com.ruoyi.edh.domain.vo.EdhProfitVo;
import com.ruoyi.edh.mapper.EdhProfitMapper;
import com.ruoyi.edh.service.IEdhProfitService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


/**
 * 易订货-收益Service业务层处理
 * 
 * @author xxx
 * @date 2020-09-02
 */
@Service
public class EdhProfitServiceImpl implements IEdhProfitService
{
    @Autowired
    private EdhProfitMapper edhProfitMapper;

    /**
     * 查询易订货-收益
     * 
     * @param id 易订货-收益ID
     * @return 易订货-收益
     */
    @Override
    public EdhProfit selectEdhProfitById(Long id)
    {
        return edhProfitMapper.selectEdhProfitById(id);
    }

    /**
     * 获取本人的收益情况
     */
    @Override
    public EdhProfit getMineProfit() {
        Long userId = SecurityUtils.getUserId();
        EdhProfit edhProfit = new EdhProfit();
        edhProfit.setCreateBy(userId.toString());
        List<EdhProfit> edhProfits = edhProfitMapper.selectEdhProfitList(edhProfit);
        if (!edhProfits.isEmpty()){
            edhProfit = edhProfits.get(0);
        }else{
            edhProfit.setAllBenefits(new BigDecimal(0));
            edhProfit.setFreeze(new BigDecimal(0));
            edhProfit.setMyBenefits(new BigDecimal(0));
            edhProfit.setNotWithdrawn(new BigDecimal(0));
            edhProfit.setTeamBenefits(new BigDecimal(0));
            edhProfit.setTodayBenefits(new BigDecimal(0));
            edhProfit.setWithdrawn(new BigDecimal(0));
            edhProfitMapper.insertEdhProfit(edhProfit);
        }
        return edhProfit;
    }

    /**
     * 查询易订货-收益列表
     * 
     * @param edhProfit 易订货-收益
     * @return 易订货-收益
     */
    @Override
    public List<EdhProfitVo> selectEdhProfitList(EdhProfitVo edhProfit)
    {
        return edhProfitMapper.queryEdhProfitList(edhProfit);
    }

    /**
     * 新增易订货-收益
     * 
     * @param edhProfit 易订货-收益
     * @return 结果
     */
    @Override
    public int insertEdhProfit(EdhProfit edhProfit)
    {
        edhProfit.setCreateTime(DateUtils.getNowDate());
        return edhProfitMapper.insertEdhProfit(edhProfit);
    }

    /**
     * 修改易订货-收益
     * 
     * @param edhProfit 易订货-收益
     * @return 结果
     */
    @Override
    public int updateEdhProfit(EdhProfit edhProfit)
    {
        return edhProfitMapper.updateEdhProfit(edhProfit);
    }

    /**
     * 批量删除易订货-收益
     * 
     * @param ids 需要删除的易订货-收益ID
     * @return 结果
     */
    @Override
    public int deleteEdhProfitByIds(Long[] ids)
    {
        return edhProfitMapper.deleteEdhProfitByIds(ids);
    }

    /**
     * 删除易订货-收益信息
     * 
     * @param id 易订货-收益ID
     * @return 结果
     */
    @Override
    public int deleteEdhProfitById(Long id)
    {
        return edhProfitMapper.deleteEdhProfitById(id);
    }
}
